﻿using System;
using System.Linq;
using Framework.Poco;
using Shell.DomainDot;
using System.Data.Entity.Validation;

namespace Framework.Domain
{
    public class AgencyMarkContext : DomainDotBase
    {
        public WithAll<Agency> Agencies { get; set; }

        public void SetAgencyMark(Guid agencyIdentity, string agencyMark)
        {
            var agency = this.Agencies.SingleOrDefault(a => a.Id.Equals(agencyIdentity));
            if (agency != null)
            {
                agency.MapMark = agencyMark;
                try
                {
                    this.Agencies.Submit();
                }
                catch (DbEntityValidationException e)
                {

                }
            }
        }

        public string GetAgencyMark(Guid agencyIdentity)
        {
            var agency = this.Agencies.SingleOrDefault(a => a.Id.Equals(agencyIdentity));
            if (agency != null)
            {
                return agency.MapMark;
            }
            return String.Empty;
        }
    }
}
